package com.zhn.resourcej.controller;


import com.zhn.resourcej.entity.User;
import com.zhn.resourcej.service.IUserService;
import com.zhn.resourcej.web.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mr.Seaning
 * @since 2023-12-04
 */
@RestController
@RequestMapping("/user")
@Api(tags ="用户")
@RequiredArgsConstructor
public class UserController {

    private final IUserService userService;
    @GetMapping("/list")
    @ApiOperation("查询用户列表")
    public Result list(){
        List<User> list = userService.list();
        return Result.success("成功",list);
    }

    @PostMapping("/add")
    @ApiOperation("添加用户")
    public Result add(@RequestBody User user){
        userService.save(user);
        return Result.success("成功");
    }

    @PostMapping("/update")
    @ApiOperation("修改用户")
    public Result update(@RequestBody User user){
        userService.updateById(user);
        return Result.success("成功");
    }

    @PostMapping("/delete/{id}")
    @ApiOperation("删除用户")
    public Result delete(@PathVariable Integer id){
        userService.removeById(id);
        return Result.success("成功");
    }
}
